package com.qf.commons.core.utils;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

/**
 * 在没有被IOC容器管理的类中，手动获取Bean
 * 值得学习
 */

public class ApplicationUtils implements ApplicationContextAware {

    private static ApplicationContext context;

    public static <T> T getBean(Class<T> tClass){
        return context.getBean(tClass);
    }
    /**
     * 将当前的IOC容器对象，作为参数传递过来
     * @param applicationContext
     * @throws BeansException
     */
    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        context=applicationContext;
    }
}
